// bttDoc.cpp : implementation of the CbttDoc class
//

#include "stdafx.h"
#include "btt.h"

#include "bttDoc.h"
#include "bttView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CbttDoc

IMPLEMENT_DYNCREATE(CbttDoc, CDocument)

BEGIN_MESSAGE_MAP(CbttDoc, CDocument)
	ON_COMMAND(ID_VIEW_3WIDTHGRID, &CbttDoc::OnView3widthgrid)
	ON_COMMAND(ID_VIEW_4WIDTHGRID, &CbttDoc::OnView4widthgrid)
	ON_COMMAND(ID_VIEW_5WIDTHGRID, &CbttDoc::OnView5widthgrid)
	ON_COMMAND(ID_VIEW_6WIDTHGRID, &CbttDoc::OnView6widthgrid)
	ON_COMMAND(ID_VIEW_7WIDTHGRID, &CbttDoc::OnView7widthgrid)
END_MESSAGE_MAP()


// CbttDoc construction/destruction

CbttDoc::CbttDoc()
{
	// TODO: add one-time construction code here

}

CbttDoc::~CbttDoc()
{
}

BOOL CbttDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}




// CbttDoc serialization

void CbttDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}


// CbttDoc diagnostics

#ifdef _DEBUG
void CbttDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CbttDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

BOOL CbttDoc::SwitchToView(CRuntimeClass* pNewViewClass)
{
  CFrameWnd* pMainWnd = (CFrameWnd*)AfxGetMainWnd();
  CView* pOldActiveView = pMainWnd->GetActiveView();

  // If we're already displaying this kind of view, no need to go further.
  if (pOldActiveView->IsKindOf(pNewViewClass))
    return TRUE;
  
  // Set the child window ID of the active view to AFX_IDW_PANE_FIRST.
  // This is necessary so that CFrameWnd::RecalcLayout will allocate
  // this "first pane" to that portion of the frame window's client
  // area not allocated to control bars. Set the child ID of
  // the previously active view to some other ID.
  ::SetWindowLong(pOldActiveView->m_hWnd, GWL_ID, 0);

  // create the new view
  CCreateContext context;
  context.m_pNewViewClass = pNewViewClass;
  context.m_pCurrentDoc = this;
  CView* pNewView = STATIC_DOWNCAST(CView, pMainWnd->CreateView(&context));
  if (pNewView != NULL)
  {
    // the new view is there, but invisible and not active...
    pNewView->ShowWindow(SW_SHOW);
    pNewView->OnInitialUpdate();
    pMainWnd->SetActiveView(pNewView);
    pMainWnd->RecalcLayout();

    // destroy the old view...
    pOldActiveView->DestroyWindow();
    return TRUE;
  }

  return FALSE;
}

// CbttDoc commands

void CbttDoc::OnView3widthgrid()
{
	CRuntimeClass* pNewViewClass = RUNTIME_CLASS(CbttView);

	CbttDoc::SwitchToView(pNewViewClass);
}

void CbttDoc::OnView4widthgrid()
{
	CRuntimeClass* pNewViewClass = RUNTIME_CLASS(CbttView4);

	CbttDoc::SwitchToView(pNewViewClass);
}

void CbttDoc::OnView5widthgrid()
{
	CRuntimeClass* pNewViewClass = RUNTIME_CLASS(CbttView5);

	CbttDoc::SwitchToView(pNewViewClass);
}

void CbttDoc::OnView6widthgrid()
{
	CRuntimeClass* pNewViewClass = RUNTIME_CLASS(CbttView6);

	CbttDoc::SwitchToView(pNewViewClass);
}

void CbttDoc::OnView7widthgrid()
{
	CRuntimeClass* pNewViewClass = RUNTIME_CLASS(CbttView7);

	CbttDoc::SwitchToView(pNewViewClass);
}
